package com.apanal.qlife.sys.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.apanal.qlife.common.constants.Constants;
import com.apanal.qlife.common.page.Page;
import com.apanal.qlife.common.page.PageReturn;
import com.apanal.qlife.sys.model.SysLog;
import com.apanal.qlife.sys.service.SysLogService;

/**
 * 系统操作日志控制类
 * 
 * 
 * @author shuliangxing
 * 
 * @date 2015-7-21下午5:20:44
 */
@Controller
@RequestMapping("/syslog")
public class SysLogController {

	@Autowired
	private SysLogService service;

	/**
	 * 分页查询
	 * 
	 * @param log
	 * @param page
	 * @param model
	 * @return
	 */
	@RequiresPermissions("sys:syslog:view")
	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String list(SysLog log, Page page, Model model) {
		PageReturn<SysLog> result = service.selectRelationForPage(log, page);
		model.addAttribute(Constants.DEFAULT_RESULT_NAME, result);
		return "sys/sysLogList";
	}

	/**
	 * 转向详情页面
	 * 
	 * @param id
	 * @param model
	 * @return
	 */
	@RequiresPermissions("sys:syslog:view")
	@RequestMapping(value = "/{id}/detail", method = RequestMethod.GET)
	public String toDetail(@PathVariable("id") Long id, Model model) {
		model.addAttribute("log", service.selectById(id));
		model.addAttribute("op", "查看日志");
		return "sys/sysLogDetail";
	}

}
